<div class="span12">
    <div class="box box-color box-bordered">
        <div class="box-title">
            <h3>
                <i class="icon-table"></i>
                Precios
            </h3>
            <div class="actions">
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_ORDER'))) { ?>
                    <a href="#mdlOrder" role="button" class="btn" data-toggle="modal"><i class="icon-table"></i></a>
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_FILTER'))) { ?>
                    <!--a href="#mdlFilter" role="button" class="btn" data-toggle="modal"><i class="icon-search"></i></a-->
                <?php } ?>
                <?php if (myCapability::testcap($caps, myCapability::C('CAP_M_ADMIN_EXCEL'))) { ?>
                    <a href="<?php echo url_for('/prices/excelPrices');?>?id=<?php echo $_GET['id'];?>" role="button" class="btn" ><i class="icon-download-alt"></i></a>
                <?php } ?>
              
            </div>
        </div>
        <div class="box-content nopadding">
            
            <?php //echo $userOrderCount;die();
            
            if($userOrderCount !=0){
            ?>
            <table class="table table-bordered dataTable dataTable-scroll-x">
                <thead>
                    <tr>
                        <?php 
                        foreach ($userTableOrder as $value) {?>
                            
                       
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==37 && $value['UserTableOrder'][0]['visible']==1){?><th>Producto</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==38 && $value['UserTableOrder'][0]['visible']==1){?><th>Precio</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==39 && $value['UserTableOrder'][0]['visible']==1){?><th>Código Proveedor</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==40 && $value['UserTableOrder'][0]['visible']==1){?><th>Categoría</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==41 && $value['UserTableOrder'][0]['visible']==1){?><th>Marca</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==42 && $value['UserTableOrder'][0]['visible']==1){?><th>Unidades</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==43 && $value['UserTableOrder'][0]['visible']==1){?><th>Precio Sugerido</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==44 && $value['UserTableOrder'][0]['visible']==1){?><th>Precio Hoy</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==45 && $value['UserTableOrder'][0]['visible']==1){?><th>Precio Semanal</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==46 && $value['UserTableOrder'][0]['visible']==1){?><th>Diferencia</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==47 && $value['UserTableOrder'][0]['visible']==1){?><th>Precio Semana 1</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==48 && $value['UserTableOrder'][0]['visible']==1){?><th>Promedio Semanal</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==49 && $value['UserTableOrder'][0]['visible']==1){?><th>Máximo</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==50 && $value['UserTableOrder'][0]['visible']==1){?><th>Mínimo</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==51 && $value['UserTableOrder'][0]['visible']==1){?><th>Desviación</th><?php }?>
                        <?php if($value['UserTableOrder'][0]['id_tablecolumn']==52 && $value['UserTableOrder'][0]['visible']==1){?><th>Competidores</th><?php }?>
                        
                        
                        <?php }?>
                    </tr>
                </thead>
                <tbody>
                    
                        <?php
                        $dataArray = array();
                        $i = 0;
                        foreach ($prices as $value) {

                            $dataArray[$i][]['producto'] = $value['name'];
                            $dataArray[$i][]['precio'] = $value['name'];
                            $dataArray[$i][]['codProveedor'] = $value['name'];
                            $dataArray[$i][]['categoria'] = $value['name'];
                            $dataArray[$i][]['marca'] = $value['name'];
                            $dataArray[$i][]['unidades'] = $value['name'];
                            $dataArray[$i][]['pSugerido'] = $value['name'];
                            $dataArray[$i][]['pHoy'] = $value['name'];
                            $dataArray[$i][]['pSemanal'] = $value['name'];
                            $dataArray[$i][]['diferencia'] = $value['name'];
                            $dataArray[$i][]['pSemana1'] = $value['name'];
                            $dataArray[$i][]['promedioS'] = $value['name'];
                            $dataArray[$i][]['maximo'] = $value['name'];
                            $dataArray[$i][]['minimo'] = $value['name'];
                            $dataArray[$i][]['desviacion'] = $value['name'];
                            $dataArray[$i][]['competidores'] = $value['name'];
                            $i++;
                        }


                        for ($x = 0; $x < $i; $x++) {
                            ?>
                            <tr>

                                        <?php foreach ($userTableOrder as $value) { ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 37 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][0]['producto']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 38 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][1]['precio']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 39 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][2]['codProveedor']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 40 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][3]['categoria']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 41 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][4]['marca']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 42 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][5]['unidades']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 43 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][6]['pSugerido']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 44 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][7]['pHoy']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 45 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][8]['pSemanal']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 46 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][9]['diferencia']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 47 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][10]['pSemana1']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 48 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][11]['promedioS']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 49 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][12]['maximo']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 50 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][12]['minimo']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 51 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][12]['desviacion']; ?></td><?php } ?>
                                            <?php if ($value['UserTableOrder'][0]['id_tablecolumn'] == 52 && $value['UserTableOrder'][0]['visible']==1) { ?><td><?php echo $dataArray[$x][12]['competidores']; ?></td><?php } ?>
                                        <?php }
                                        ?>
                            </tr>
                            <?php
                        }
                        ?>

                </tbody>
            </table>
            
            <?php }else{ ?>  
            
            <table class="table table-bordered dataTable dataTable-scroll-x">
                <thead>
                    <tr>
                        <th>Producto</th>
                        <th>Precio</th>
                        <th>Código Proveedor</th>
                        <th>Categoría</th>
                        <th>Marca</th>
                        <th>Unidades</th>
                        <th>Precio Sugerido</th>
                        <th>Precio Hoy</th>
                        <th>Precio Semanal</th>
                        <th>Diferencia</th>
                        <th>Precio Semana 1</th>
                        <th>Promedio Semanal</th>
                        <th>Máximo</th>
                        <th>Mínimo</th>
                        <th>Desviación</th>
                        <th>Competidores</th>
                    </tr>
                </thead>
                <tbody>
                        
                    <?php foreach ($prices as $value) { ?>

                        <tr>
                            <td><?php echo $value['Products']['name'];?></td>
                            <td>
                                <a href="#" id="username" data-type="text" data-pk="<?php echo $value['id_price'];?>" data-params="{store:'<?php echo $_GET['id'];?>'}" data-name="username" data-url="<?php echo url_for('prices/updatePrice');?>" data-original-title="Enter username"  data-rule-required="true"><?php echo $value['observed_price'];?></a></td>
                            <td><?php echo $value['code_supplier'];?></td>
                            <td><?php echo $value['CategoryProduct']['name'];?></td>
                            <td><?php echo $value['Brands']['name'];?></td>
                            <td><?php echo $value['units'];?></td>
                            <td><?php echo $value['price_suggested'];?></td>
                            <td><div id="price_today_<?php echo $value['id_price'];?>"><?php echo $value['price_today'];?></div></td>
                            <td><div id="price_week_<?php echo $value['id_price'];?>"><?php echo $value['price_week'];?></div></td>
                            <td><div id="price_difference_<?php echo $value['id_price'];?>"><?php echo $value['difference'];?></div></td>
                            <td><div id="price_last_week_<?php echo $value['id_price'];?>"><?php echo $value['price_week_last'];?></div></td>
                            <td><div id="price_avg_week_<?php echo $value['id_price'];?>"><?php echo $value['average_weekly'];?></div></td>
                            <td><div id="price_max_<?php echo $value['id_price'];?>"><?php echo $value['maximal'];?></div></td>
                            <td><div id="price_min_<?php echo $value['id_price'];?>"><?php echo $value['minimal'];?></div></td>
                            <td><div id="price_desviation_<?php echo $value['id_price'];?>"><?php echo $value['desviation'];?></div></td>
                            <td><?php echo $value['competitors'];?></td>
                        </tr>
                    <?php } ?>

                </tbody>
            </table>
            
            
            <?php }?>
        </div>
    </div>
</div>